package p13.code;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class TaskExecutionWebServer {

    private static final int nThread = 100;

    //创建一个大小为100的线程池
    private static final Executor exec = Executors.newFixedThreadPool(nThread);

    public static void main(String [] args) throws IOException {

        ServerSocket socket = new ServerSocket(80);
        while(true){
            final Socket connection = socket.accept();
            //新建任务，这个过程速度很快
            Runnable task = new Runnable(){
                public void run(){
                    handleRequest(connection);
                }
            };
            exec.execute(task);//将任务放入线程池，线程池会自动执行
        }
    }

    public static void handleRequest(Socket socket){
        System.out.println("处理本次请求！！！！！");
    }

}
